#!/bin/bash
#author: <fanyuantao>
#date: 2024-08-08
#desc: This script is used to clean the host cache.

function clean_host_cache() {
    echo "Cleaning host cache..."
    sync && echo 3 > /proc/sys/vm/drop_caches
    echo "Done."
    echo "current cache size:"
    free -h
}

function do_clean_host_cache() {
    echo "current cache size:"
    free -h
    read -p "Do you want to flush the host cache? (y/n) " answer
    if [[ $answer == "y" ]]; then
        clean_host_cache
    else
        echo "Cancelled."
    fi
}

function echo_result() {
    echo "success"
}

function main() {
    do_clean_host_cache
    echo_result
}

main